//
// Created by lingwu on 2021/4/23.
//

#ifndef DEMO_LINKSTRING_H
#define DEMO_LINKSTRING_H

#endif //DEMO_LINKSTRING_H

using namespace std;
typedef struct snode{
//    链串结点类型声明
    char data;
    struct snode *next;
}LinkStrNode;

void StrAssign(LinkStrNode *&l,char str[]){
//    初始化链串
LinkStrNode *s,*r;
l=(LinkStrNode*)malloc(sizeof(LinkStrNode));
r=l;
r->next=NULL;
    for (int i = 0; str[i]!='\0' ; i++) {
  s=(LinkStrNode*)malloc(sizeof(LinkStrNode));
  s->data=str[i];
  s->next=r->next;
  r->next=s;
  r=s;
    }
    r->next=NULL;

}
void DestroyStr(LinkStrNode *&l){
//    删除链串
LinkStrNode *pre=l,*p=l->next;
    while (p!=NULL){
        free(pre);
        pre=p;
        p=p->next;
    }
    free(pre);
}
int StrLength(LinkStrNode *l){
// 求出链串的长度
int i=0;
LinkStrNode  *p=l->next;
    while (p!=NULL){
        i++;
        p=p->next;
    }
    return i;
}
void DisStr(LinkStrNode *l){
//    输出链串
LinkStrNode  *p=l->next;
    while (p!=NULL){
        printf("%c",p->data);
        p=p->next;
    }
    printf("\n");
}